<?php

namespace App\Exports\Stats\User;

use App\Exports\Export;

class PlayerBetExport extends Export
{

    /**
     * 映射标题行
     *
     * @return array
     */
    protected function headings(): array
    {
        return trans('view.stats.user.player-bet.headings');
    }

    /**
     * 映射数据行
     *
     * @param \Illuminate\Database\Eloquent\Model $item
     * @return array
     */
    protected function map($item): array
    {
        return [
            timestamp_to_datetime($item->timed, $this->timedType),
            $item->uid,
            $item->org->name ?? $item->plat_code,
            $item->account_id,
            $this->games[$item->game_id] ?? $item->game_id,
            $item->currency,
            $item->bet_base,
            $item->bet_num,
            $item->gain_player,
            $item->amount,
            $item->doc_count,
            $item->usd['bet_base'],
            $item->usd['bet_num'],
            $item->usd['gain_player'],
            $item->usd['amount'],
        ];
    }

    /**
     * 时间类型
     *
     * @var string
     */
    protected $timedType;

    /**
     * 游戏
     *
     * @var array
     */
    protected $games;

    /**
     * 初始化操作
     */
    protected function init()
    {
        // 文件名称
        $this->filename = trans('view.stats.user.player-bet.filename');

        // 时间类型
        if ($this->request->is('*/exportHour')) {
            $this->timedType = 'hour';
        } elseif ($this->request->is('*/exportDay')) {
            $this->timedType = 'day';
        } elseif ($this->request->is('*/exportMonth')) {
            $this->timedType = 'month';
        }

        // 游戏
        $this->games = trans('view.game.games');
    }
}
